import axios from "axios";
import router from "@/admin/router";
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'

axios.defaults.headers.post['Content-Type'] = 'multipart/form-data';

// 请求拦截器
axios.interceptors.request.use(
    (config) => {

        //  头部携带token
        // config.headers = {
        //   token: JSON.parse(sessionStorage.getItem('token')),
        // };
        if (localStorage.getItem("adminToken")) {
            config.headers.Authorization = "Bearer " + localStorage.getItem("adminToken");

        }
        // config.headers["X-Nideshop-Token"] = sessionStorage.getItem('token')
        return config;
    },
    (error) => {
        return Promise.reject(error);
    }
);
let that = this
// 响应拦截器
axios.interceptors.response.use(
    (res) => {
        // 未设置状态码则默认成功状态
        const code = res.data.code;
        // if (code === 401) {
        // that.$confirm("登陆已过期,请重新登录", "系统提示", {
        //   confirmButtonText: "确认",
        //   cancelButtonText: "取消",
        //   type: "warning",
        // })
        //   .then(() => {
        //     router.push('login');
        //   })
        //   .catch(() => {});


        // } else if (code === 500) {
        // } else if (code === 200) {
        // } else {
        // }
        return Promise.resolve(res.data)

    },
    (error) => {
        return Promise.reject(error);
    }
);
export default axios;
